<template>
  <div class="gl_contentBox gl_heightFull noPadding">
    <div class="top_title">
      <span class="top_name">{{ title }}</span>
      <span v-if="placeNo" class="top_number gl_ml_15">{{ placeNo }}</span>
    </div>
    <div class="gl_px_15 gl_pb_15">
      <el-row class="gl_my_15">
        <el-button type="success" size="mini" :loading="btnLoading_success" @click="clickPass">一键通过</el-button>
        <el-button type="primary" size="mini" :loading="btnLoading_info" @click="exportInfo">报名信息导出</el-button>
        <el-button type="primary" size="mini" :loading="btnLoading_photo" @click="exportPhoto">照片导出</el-button>
        <div style="display:inline-block;width:80px;height:28px;margin-right:10px;margin-left:10px;">
          <el-upload
            :action="importAction"
            :http-request="upLoadFile"
            :before-upload="beforeUpload"
            :auto-upload="true"
            :show-file-list="false"
            accept=".xlsx, .xls"
          >
            <el-button :loading="btnLoading_no" type="primary" size="mini">证书编号导入</el-button>
          </el-upload>
        </div>
      </el-row>
      <el-table
        v-loading="loading"
        class="gl_table_noBorder"
        :data="tableData"
        size="mini"
      >
        <!-- <el-table-column type="selection" :selectable="selectable" label-class-name="selection" :reserve-selection="true" />-->
        <el-table-column label="序号" type="index" />>
        <el-table-column label="姓名" align="center" width="54">
          <template slot-scope="{row}">
            <PersonalImage :imgurl="row.imagePath" imgheight="60px" />
          </template>
        </el-table-column>
        <el-table-column label="" min-width="80">
          <template slot-scope="{row}">
            {{ row.studentName || '--' }}
          </template>
        </el-table-column>
        <el-table-column label="证件号" prop="idCardNumber" :width="145" />
        <el-table-column label="联系方式" prop="phoneNumber" :width="95" />
        <el-table-column label="当前级别" width="78">
          <template slot-scope="{ row }">
            <span v-if="row.levelType && row.duanType">{{ row.levelType.name + ' / ' + row.duanType.name }}</span>
            <span v-else>{{ row.levelType ? row.levelType.name : '' }} {{ row.duanType ? row.duanType.name : '' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="申报级别" :min-width="80">
          <template slot-scope="{row}">
            <span v-for="(item, index) in row.duanExamStudentDuans" :key="item.duanId">
              {{ item.duan ? item.duan.name : '' }} {{ row.duanExamStudentDuans.length - 1 === index ? '': '/' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="教练" prop="coachName" :min-width="80" />
        <el-table-column label="机构" prop="organizationUnitName" :min-width="120" />
        <el-table-column label="成绩" prop="score" width="70" />
        <el-table-column label="考官" prop="duanExamOfficialName" :min-width="80" />
        <el-table-column label="考官编号" prop="duanExamOfficial.no" :min-width="100" />
        <el-table-column label="缴费类型" prop="memberFeeType.name" :width="68" />
        <el-table-column label="缴费年限" prop="paymentYearTime" :width="68" />
        <el-table-column label="会费金额" prop="memberAmount" :width="68">
          <template slot-scope="{row}">
            {{ (row.memberAmount / 100).toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column label="申报金额" prop="requestAmount" :width="68">
          <template slot-scope="{row}">
            {{ (row.requestAmount / 100).toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column label="其他费用" prop="otherAmount" :width="68">
          <template slot-scope="{row}">
            {{ (row.otherAmount / 100).toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column label="会员号" prop="ctaMemberId" :min-width="100" />
        <el-table-column label="到期时间" :width="90">
          <template slot-scope="{row}">
            <span v-if="row.ctaMemberExipry">
              {{ row.ctaMemberExipry | FormatDate('yyyy-MM-dd') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="证书编号" prop="certificateNumber" />
        <el-table-column label="考试结果" prop="scoreStatus.name" />
        <el-table-column label="审核结果" prop="toScoreStatus.name" />
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="{ row }">
            <el-button size="mini" type="text" @click="clickReview('Approved', row.id)">通过</el-button>
            <el-button size="mini" type="text" @click="clickReview('NotApproved', row.id)">不通过</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-row class="gl_mt_15" style="text-align: right;">
        <el-pagination
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="qo.MaxResultCount"
          :current-page="qo.Page"
          @size-change="changePageSize"
          @current-change="changePage"
        />
      </el-row>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import PersonalImage from '@/components/PersonalImage/index';
import { api_GET_DownLoadFileAddHeader, api_Post_UploadFileAddHeader } from '@/extend/api/file';
import { errorText } from '@/lib';
import {
  Api_GET_ClubDuanExamStudentScoreExamReportStudentScoreQO, // 获取考试的学生上传完成绩单之后的成绩
  ApprovalScoreRegistrationInput // 审核上传完成的成绩单中的学生成绩
} from '@/lib/form/hall/swaggerForm';
import {
  api_GET_ClubDuanExamStudentScoreExamReportStudentScore, // 获取考试的学生上传完成绩单之后的成绩
  api_POST_ClubDuanExamStudentScoreApprovalExamReportScore, // 审核上传完成的成绩单中的学生成绩
  api_POST_ClubDuanExamStudentScoreOnKeyApprovalExamReportScoreDuanExamId // 一键审批上传完成的成绩单中的学生成绩
  // api_GET_ClubExportExamStudentHeadImage // 导出成绩单考试下的学生头像
} from '@/extend/api/hallswaggerApi/app';
export default {
  components: {
    PersonalImage
  },
  data () {
    return {
      title: '',
      placeNo: '',
      qo: new Api_GET_ClubDuanExamStudentScoreExamReportStudentScoreQO(),
      importAction: `${WEB_CONFIG.VUE_APP_SWAGGER_HALL_BASE}/api/app/club/ImportCertificateNumber`,
      tableData: [],
      loading: false,
      total: 0,
      chooseTime: [],
      btnLoading_success: false,
      btnLoading_info: false,
      btnLoading_photo: false,
      btnLoading_no: false,
      selectData: [],
      DuanExamId: '',
      GetDuanExamStudentsInput: {},
      file: ''
    };
  },
  computed: {
    ...mapState({
      tenantId: state => state.user.tenantId,
      user: state => state.user.currentOU
    })
  },
  created() {
    this.DuanExamId = this.$route.query.id || '';
    this.title = this.$route.query.name || '';
    this.placeNo = this.$route.query.no || '';
    this.getPageList();
  },
  methods: {
    getPageList(page) {
      this.qo.Page = page || 1;
      this.qo.SkipCount = (this.qo.Page - 1) * this.qo.MaxResultCount;
      this.qo.DuanExamId = this.DuanExamId;
      this.qo.IncludeRegisterStudent = true;
      this.qo.IncludeDuanExamOfficial = true;
      this.qo.IncludeLevelType = true;
      this.qo.IncludeDuanType = true;
      this.qo.IsApproved = true;
      this.qo.IncludeMemberFeeType = true;
      this.qo.IncludeDuanExamRequestDuans = true;
      this.qo.IncludeScoreStatus = true;
      this.qo.IncludeToScoreStatus = true;
      this.qo.IncludeDuanExamFees = true;
      this.qo.ScoreStatusCode = 'Approved';
      this.qo.IncludeRegisterStudent = true;
      this.qo.Sorting = 'creationTime DESC';
      this.loading = true;
      api_GET_ClubDuanExamStudentScoreExamReportStudentScore(this.qo).then(res => {
        this.loading = false;
        this.tableData = res.items;
        this.total = res.totalCount;
      }, error => {
        this.loading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 通过不通过
    clickReview(code, id) {
      const qo = new ApprovalScoreRegistrationInput();
      qo.scoreStatusCode = code;
      qo.duanExamStudentIds = [id];
      this.loading = true;
      api_POST_ClubDuanExamStudentScoreApprovalExamReportScore(qo).then(res => {
        this.loading = false;
        this.$message({ type: 'success', message: '审核成功' });
        this.getPageList(this.qo.Page);
      }, error => {
        this.loading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 一键通过
    clickPass() {
      this.btnLoading_success = true;
      api_POST_ClubDuanExamStudentScoreOnKeyApprovalExamReportScoreDuanExamId(this.DuanExamId, { scoreStatusCode: 'Approved' }).then(res => {
        this.btnLoading_success = false;
        this.$message({ type: 'success', message: '操作成功' });
        this.getPageList(this.qo.Page);
      }, error => {
        this.btnLoading_success = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 照片导出
    exportPhoto() {
      const that = this;
      this.btnLoading_photo = true;
      const tempUrl = `/api/app/club/ExportExamStudentHeadImage`;
      const fileName = '考生照片' + '.zip';
      const params = { duanExamId: this.DuanExamId, scoreStatusCode: 'Approved' };
      const baseUrl = WEB_CONFIG.VUE_APP_SWAGGER_HALL_BASE;
      api_GET_DownLoadFileAddHeader(tempUrl, fileName, params, baseUrl).then(res => {
        this.btnLoading_photo = false;
      }).catch(error => {
        that.btnLoading_photo = false;
        errorText(error).then(function(text) {
          that.$message({ type: 'error', message: text });
        });
      });
    },
    // 报名信息
    exportInfo() {
      const that = this;
      this.btnLoading_info = true;
      const tempUrl = `/api/excel`;
      const fileName = '报名信息' + '.xlsx';
      this.GetDuanExamStudentsInput = {
        IsCurrentOrgStudentScore: false,
        DuanExamId: this.DuanExamId,
        IncludeDuanExamOfficial: true,
        IncludeLevelType: true,
        IncludeDuanType: true,
        IsApproved: true,
        IncludeMemberFeeType: true,
        IncludeDuanExamRequestDuans: true,
        IncludeScoreStatus: true,
        IncludeToScoreStatus: true,
        IncludeDuanExamFees: true,
        ScoreStatusCode: 'Approved',
        Sorting: 'creationTime DESC'
      };
      this.GetDuanExamStudentsInput = JSON.stringify(this.GetDuanExamStudentsInput);
      const baseUrl = WEB_CONFIG.VUE_APP_SWAGGER_HALL_BASE;
      api_GET_DownLoadFileAddHeader(tempUrl, fileName, { reportName: 'ExamReportStudentScore', GetDuanExamStudentsInput: this.GetDuanExamStudentsInput }, baseUrl).then(res => {
        this.btnLoading_info = false;
      }).catch(error => {
        that.btnLoading_info = false;
        errorText(error).then(function(text) {
          that.$message({ type: 'error', message: text });
        });
      });
    },
    // 证书编号导入
    beforeUpload(file) {
      this.file = file;
    },
    upLoadFile() {
      this.btnLoading_no = true;
      api_Post_UploadFileAddHeader(this.importAction, this.file, { duanExamId: this.DuanExamId }).then(res => {
        this.btnLoading_no = false;
        this.$message({ type: 'success', message: '导入成功' });
        this.getPageList();
      }).catch(error => {
        this.btnLoading_no = false;
        this.$message({ type: 'error', message: '导入失败 ' + error.error || error.error.message });
      });
    },
    // 分页
    changePage(page) {
      this.getPageList(page);
    },
    changePageSize(pagesize) {
      this.qo.MaxResultCount = pagesize;
      this.getPageList();
    }
    // 处理选中行
    // selection(val) {
    //   this.selectData = val;
    // },
    // 审核通过行禁选
    // selectable(row, index) {
    //   if (row.id === '12345') {
    //     return false;
    //   }
    //   return true;
    // },
  }
};
</script>

<style lang="scss" scoped>
.noPadding {
  padding: 0px;
}
.top_title {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #E8E8E8;
  padding-left: 25px;
}
.top_name {
  font-size: 16px;
  font-weight: bold;
}
.top_number {
  font-size: 14px;
}
.upload_file {
  width: 200px;
  display: inline-block;
}
</style>
